package com.chen.generator;
import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.nio.file.Paths;
import java.util.Collections;

public class MPGenerator {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://10.211.55.100:3306/tingshu", "root", "1234")
                .globalConfig(builder -> builder
                        .author("chen")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/Test-generator/src/main/java") //生成文件的位置
                        .commentDate("yyyy-MM-dd")
                )
                .packageConfig(builder -> builder
                        .parent("com.chen")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .pathInfo(Collections.singletonMap(
                                OutputFile.xml,
                                System.getProperty("user.dir") + "/Test-generator/src/main/resources/mapper"
                        )) //对生成的.xml文件单独配置
                )
                .strategyConfig(builder -> builder
                        .addInclude("user")  //告诉mp需要生成那张表
                        .entityBuilder().enableLombok()
                        .enableTableFieldAnnotation() // 启用字段注解,会在实体类的属性上,加上对应数据库的字短名
                        .serviceBuilder().formatServiceFileName("%sService")
                        .controllerBuilder().enableRestStyle() //开启rest风格
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
